package com.dream;

import com.dream.rpc.config.RpcConfig;
import com.dream.rpc.constant.RpcConstant;
import com.dream.rpc.utils.ConfigUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * Hello world!
 *
 * @author Dreamer
 */

@Slf4j
public class RpcApp
{

    private static volatile RpcConfig rpcConfig;


    /**
     * 默认配置初始化
     */
    public static void init() {
        RpcConfig newRpcConfig;

        try {
            newRpcConfig = ConfigUtils.loadConfig(RpcConfig.class, RpcConstant.DEFAULT_CONFIG_PREFIX);
        } catch (Exception e) {
            //配置失败使用默认值
            newRpcConfig = new RpcConfig();
        }

        init(newRpcConfig);
    }

    public static void init(RpcConfig newRpcConfig) {
        rpcConfig = newRpcConfig;
        log.info("rpc-init ------");

    }


    public static RpcConfig getRpcConfig() {

        if (rpcConfig == null) {
            synchronized (RpcApp.class) {
                if (rpcConfig == null) {
                    init();
                }
            }
        }
        return rpcConfig;
    }





    public static void main( String[] args )
    {

    }



}
